package com.carcenter.xxljob.handler;



import com.carcenter.common.pojo.store.MyPageData;
import com.carcenter.common.pojo.store.SearchStoreDto;
import com.carcenter.common.result.Result;
import com.carcenter.common.result.enums.impl.ResultCode;
import com.store.client.StoreApi;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.awt.print.Book;
import java.util.List;

@Slf4j
@Component
public class SampleXxlJob {
    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    StoreApi storeApi;

    //SampleXxlJob.class，handler名字是SampleXxlJob
    private static Logger logger = LoggerFactory.getLogger(SampleXxlJob.class);


    /**
     * 2、分片广播任务
     */
    @XxlJob("SampleXxlJob")
    public void updateStoreList() throws Exception {
        // 清除相关缓存（根据业务规则确定需要清除哪些缓存键）
        redisTemplate.delete(
                redisTemplate.keys("store:list:*") // 删除所有门店列表缓存
        );
        SearchStoreDto searchStoreDto = new SearchStoreDto();

        Result<MyPageData> storeList = storeApi.getStoreList(1, 4, searchStoreDto);
        if (storeList!=null && storeList.getCode()== ResultCode.SUCCESS.getCode() ) {
            MyPageData data = storeList.getData();
            if (data.getList().size()>0) {
                log.info("门店库存定时更新成功！！！");
            }
        }

    }
}
